home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: Locaton of an array?
- Date: 12 Jan 1996 18:28:44 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4d698s$g4r@news.iag.net>
- References: <4d4iqk$hs3@overload.lbl.gov>
- NNTP-Posting-Host: pm1-orl25.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4d4iqk$hs3@overload.lbl.gov>, mfaiguen says...
- >
- >I am sure this has been answered a million times by now, but could someody
- help
- >me, please?
- >
- >I have an array in my program, and I need to find out the absolute location
- in
- >memory where this array is located.
- >I have tried to do it this way:
- >
- >#include <stdio.h>
- >
- >int main() {
- > char arr[10];
- > int addr;
- >
- > printf("sizeof(char *) = %d\n", sizeof(char *));
- > printf("sizeof(int) = %d\n", sizeof(int));
- >
- > addr = arr;
-
- Your compiler allowed this?? Try:
-
- #include <stdio.h>
-
- int main()
- {
- char arr[10];
- void *ptr = arr;
-
- printf( "The address of arr is: %p\n", (void*)arr);
- printf( "The address of arr is: %p\n", ptr);
-
- return 0;
- }
-
- I believe the c.l.c faq (Frequently Asked Question) list has a discussion
- on this. It is available for anonymous ftp from rtfm.mit.edu
- /pub/usenet/comp.lang.c.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-